﻿namespace EmployeeSystem.Migrations
{
    using Models;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<EmployeeSystemContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
            ContextKey = "EmployeeSystem.Models.EmployeeSystemContext";
        }

        protected override void Seed(EmployeeSystemContext context)
        {
            var defaultDepartment = new Department { Id = Guid.NewGuid(), Name = "商业应用事业部" };

            context.Departments.AddOrUpdate(
              p => p.Name,
              defaultDepartment
            );

            var generalManager = new Job { Id = Guid.NewGuid(), JobTitle = "总经理" };
            var projectManager = new Job { Id = Guid.NewGuid(), JobTitle = "项目经理" };

            context.Jobs.AddOrUpdate(
              p => p.JobTitle,
              generalManager,
              projectManager
            );

            context.Employees.AddOrUpdate(
              p => p.Name,
              new Employee { Id = Guid.NewGuid(), ExternalId = "WS001", Name = "许建国", Contract = new Contract { Id = Guid.NewGuid(), Salary = 50000, EffectiveDate = new DateTime(2016, 1, 1), ExpirationDate = new DateTime(2020, 1, 1) }, Department = defaultDepartment, Job = generalManager },
              new Employee { Id = Guid.NewGuid(), ExternalId = "WS002", Name = "朱俊阳", Contract = new Contract { Id = Guid.NewGuid(), Salary = 20000, EffectiveDate = new DateTime(2016, 2, 1), ExpirationDate = new DateTime(2020, 2, 1) }, Department = defaultDepartment, Job = projectManager }
            );

        }
    }
}
